/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rule;

import java.util.HashSet;

/**
 *
 * @author Daniel Gribel
 */
public class AtLeastOneSpecialChar extends Clause {

    private int contSimbs = 0;
    
    public AtLeastOneSpecialChar(String p) {
        super(p);
    }

    @Override
    public boolean checkConditions() {
        
        HashSet<Character> simbols = getSpecialChars();
        
        for (int i = 0; i < getPass().length(); i++) {
            if(simbols.contains(getPass().charAt(i)))
                contSimbs++;
        }

        if (contSimbs >= 1) {
            punctuate(getScore() + 5);
            setLog("5 points for at least one special char");
            return true;
        }
        
        return false;
    }

    @Override
    public String outputMessage() {
        return getLog();
    }
    
    private HashSet<Character> getSpecialChars() {
        HashSet<Character> simbols = new HashSet<Character>();
        simbols.add('!');
        simbols.add('@');
        simbols.add('#');
        simbols.add('$');
        simbols.add('%');
        simbols.add('^');
        simbols.add('&');
        simbols.add('*');
        simbols.add('?');
        simbols.add('_');
        simbols.add('~');
        return simbols;
    }
    
    public int count(){
        return contSimbs;
    }
    
}
